import maya.cmds as mc

import LZ_public_command.LZ_controllar_command
reload( LZ_public_command.LZ_controllar_command )

import LZ_public_command.LZ_rename_command
reload( LZ_public_command.LZ_rename_command)

import LZ_public_command.LZ_general_command
reload(LZ_public_command.LZ_general_command)

import LZ_public_command.LZ_rivet
reload(LZ_public_command.LZ_rivet)

import LZ_public_command.LZ_skinCluster
reload(LZ_public_command.LZ_skinCluster)

import LZ_public_command.LZ_blendshape_command
reload(LZ_public_command.LZ_blendshape_command)

import LZ_public_command.LZ_sdk_command
reload(LZ_public_command.LZ_sdk_command)

import LZ_public_command.LZ_Attribute
reload(LZ_public_command.LZ_Attribute)

import LZ_public_command.LZ_skinCluster
reload(LZ_public_command.LZ_skinCluster)


class createEyeSetting(LZ_public_command.LZ_controllar_command.LZ_controllar_command , 
                      LZ_public_command.LZ_rename_command.rename_commands ,
                      LZ_public_command.LZ_general_command.general_command ,
                      LZ_public_command.LZ_rivet.LZ_rivetClass ,
                      LZ_public_command.LZ_skinCluster.LZ_skinCluster,
                      LZ_public_command.LZ_blendshape_command.LZ_blendshape_command,
                      LZ_public_command.LZ_sdk_command.LZ_sdk_command,
                      LZ_public_command.LZ_Attribute.LZ_attribute,
                      LZ_public_command.LZ_skinCluster.LZ_skinCluster
                      
                      ):
    def __init__(self):
        pass
    def createEyeTemple(self,prefix = '' ,ifMirror = 1 , orgPre = 'lf_' , targetPre = 'rt_' ):
        
        eyeSocketTemInfo = [ ('ac_lf_innersocket_temloc', ( 1.774,182.0,9.088 ) ) ,
                             ('ac_lf_uppersocket1_temloc', ( 2.876,183.733,9.2 ) ) ,
                             ('ac_lf_uppersocket2_temloc', ( 4.97,184.28,8.854 ) ) ,     
                             ('ac_lf_uppersocket3_temloc', ( 6.891,183.73,7.803 ) ) ,   
                             ('ac_lf_outersocket_temloc', ( 7.943,182.474,6.0 ) ) ,
                             ('ac_lf_lowersocket3_temloc', ( 7.239,180.052,7.144 ) ) ,
                             ('ac_lf_lowersocket2_temloc', ( 4.879,179.414,8.646 ) ) ,
                             ('ac_lf_lowersocket1_temloc', ( 2.931,180.057,9.017 ) ) 
                             
                              ]
                              
        eyeLidTemInfo = [ ('ac_lf_innerlid_temloc', ( 2.164,182.05,8.68 ) ) ,
                             ('ac_lf_upperlid1_temloc', ( 2.992,183.383,9.01 ) ) ,
                             ('ac_lf_upperlid2_temloc', ( 4.97,183.864,8.977 ) ) ,     
                             ('ac_lf_upperlid3_temloc', ( 6.83,183.346,7.904 ) ) ,   
                             ('ac_lf_outerlid_temloc', ( 7.562,182.589,6.614 ) ) ,
                             ('ac_lf_lowerlid3_temloc', ( 6.754,181.144,7.531 ) ) ,
                             ('ac_lf_lowerlid2_temloc', ( 4.822,180.425,8.4 ) ) ,
                             ('ac_lf_lowerlid1_temloc', ( 3.158,180.796,8.52 ) ) 
                             
                              ]                   
        eye_center = ('ac_lf_eye_temloc',(4.045,182.705,5.384))
        eyecrunch = ('ac_lf_eyecrunch_temloc',(0.543,185.021,11.539))
        
        eye_Temloc_grp = prefix + 'lf_eye_temloc_grp'
        eyelid_Temloc_grp = prefix + 'lf_eyelid_temloc_grp'
        eye_Temloc_grp_rt = str( eye_Temloc_grp ).replace(orgPre, targetPre)
        eyelid_Temloc_grp_rt = str( eyelid_Temloc_grp ).replace(orgPre, targetPre)
        
        eyecenter = prefix + str(eye_center[0]) 
        temloc_eyecrunch = prefix + str(eyecrunch[0]) 
        eye_socket_all = []
        eye_all = []
        if mc.objExists(eye_Temloc_grp) ==0:
            self.createTransformer( locName = eye_Temloc_grp ,position = (0,0,0) ,rotation = ( 0,0,0) ,type = 'group',LocPosion = (0,0,0))
            
            
            self.createTransformer( locName = eyelid_Temloc_grp ,position = (0,0,0) ,rotation = ( 0,0,0) ,type = 'group',LocPosion = (0,0,0))
            
            mc.parent(  eyelid_Temloc_grp , eye_Temloc_grp )
            
            temloc_eyecrunch = prefix + eyecrunch[0]
            self.createTransformer( locName = temloc_eyecrunch ,position = eyecrunch[1],rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
            mc.parent(  temloc_eyecrunch , eye_Temloc_grp )
            if ifMirror == 1 :
                temloc_eyecrunch_rt = str(temloc_eyecrunch).replace( 'lf_' ,'rt_')
                self.createTransformer( locName = temloc_eyecrunch_rt ,position = (eyecrunch[1][0]*-1,eyecrunch[1][1],eyecrunch[1][2]),rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
                mc.parent(  temloc_eyecrunch_rt , eye_Temloc_grp )
            
            for est in  eyeSocketTemInfo:
                
                est_temple = prefix + est[0]
                
                if mc.objExists( est_temple  )== 0 :   
                    self.createTransformer( locName = est_temple ,position = est[1],rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
                    mc.parent( est_temple , eye_Temloc_grp )
                    self.setCtrlColor( 17 ,est_temple)
                    
                    eye_socket_all.append(est_temple)
                    if ifMirror == 1 :
      
                        if mc.objExists( eye_Temloc_grp_rt )== 0:
                            self.createTransformer( locName = eye_Temloc_grp_rt ,position = (0,0,0) ,rotation = ( 0,0,0) ,type = 'group',LocPosion = (0,0,0))
                            
                            self.createTransformer( locName = eyelid_Temloc_grp_rt ,position = (0,0,0) ,rotation = ( 0,0,0) ,type = 'group',LocPosion = (0,0,0))

                        
                            mc.parent( eyelid_Temloc_grp_rt, eye_Temloc_grp_rt )
                            
                        rt_loc  = str( est_temple ).replace( orgPre ,targetPre )
                        rt_position  = (est[1][0]*-1,est[1][1],est[1][2] )
                        
                        self.createTransformer( locName = rt_loc ,position = rt_position ,rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
                        mc.parent( rt_loc , eye_Temloc_grp_rt)
                        self.setCtrlColor( 17 ,rt_loc)
                    else:
                        pass

            for elt in  eyeLidTemInfo:
                
                est_temple = prefix + elt[0]
                
                if mc.objExists( est_temple  )== 0 :   
                    self.createTransformer( locName = est_temple ,position = elt[1],rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
     
                    mc.parent( est_temple , eyelid_Temloc_grp )
                    eye_all.append(est_temple)
                    self.setCtrlColor( 13 ,est_temple)
                    if ifMirror == 1 :
                        rt_loc  = str( est_temple ).replace(orgPre, targetPre)
                        rt_position  = (elt[1][0]*-1,elt[1][1],elt[1][2] )
                        
                        self.createTransformer( locName = rt_loc ,position = rt_position ,rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
                        mc.parent( rt_loc , eyelid_Temloc_grp_rt )
                        
                        self.setCtrlColor( 13 ,rt_loc)
                    else:
                        pass
            ###------------------------ eye center -------------            
            #eyecenter = prefix + str(eye_center[0]) 

            if mc.objExists(eyecenter) == 0:
                self.createTransformer( locName = eyecenter ,position = eye_center[1],rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
                mc.parent(eyecenter , eye_Temloc_grp )
            if ifMirror == 1 :
                eyecenter_rt = str(eyecenter).replace(orgPre, targetPre)
                if mc.objExists(eyecenter_rt) == 0:

                    rt_position_center = ( eye_center[1][0]*-1, eye_center[1][1] ,eye_center[1][2] )
                    self.createTransformer( locName = eyecenter_rt ,position = rt_position_center , rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
                    mc.parent(eyecenter_rt , eye_Temloc_grp_rt )
            
        else:
            print( eye_Temloc_grp +' already exist in the scene' )  
            
            
        #### =================================================================
        # -------------------------  create curve  ---------------------------
        
        curveSocket = prefix + 'lf_eyeSocket_temCurve'
        if mc.objExists(curveSocket) == 0:
            mc.circle( ch =False , nr =(0,1,0) , sections = 8 ,n = curveSocket )
            mc.parent(curveSocket, eye_Temloc_grp )
        defNum = 0
        for sockettem in eyeSocketTemInfo:
            
            position = mc.xform( prefix+sockettem[0] , q=True ,t=True ,ws =True )
            
            mc.xform( str(curveSocket) + '.ep['+str(defNum)+']', t=position ,ws=True)
            
            defNum = defNum+1
        
        if ifMirror == 1 :
            curveSocket_rt = str(curveSocket).replace( orgPre ,targetPre )
            if  mc.objExists(curveSocket_rt) == 0:
                mc.circle( ch =False , nr =(0,1,0) , sections = 8 ,n = curveSocket_rt )
                mc.parent(curveSocket_rt, eye_Temloc_grp_rt )
            defNum = 0
            for sockettem in eyeSocketTemInfo:
                rt_obj = str(prefix+sockettem[0]).replace( orgPre ,targetPre )
                
                position_rt = mc.xform( rt_obj , q=True ,t=True ,ws =True )
                
                mc.xform( str(curveSocket_rt) + '.ep['+str(defNum)+']', t=position_rt ,ws=True)
                
                defNum = defNum+1
        #---------------------------------------------------------
        return [eye_socket_all,eye_all,eyecenter , temloc_eyecrunch]
        
    
    #=========================================================
    #||                                                     ||
    #||             eye ball                                ||
    #||                                                     ||
    #||                                                     ||
    #=========================================================
    
    '''  
        eye_all_ctrl = prefix + 'ac_lf_eye_ctrl'
        eyeuplid_ctrl = prefix + 'ac_lf_upperlid_ctrl'
        eyelowerlid_ctrl = prefix + 'ac_lf_lowerlid_ctrl'
        eyeball_ctrl = prefix + 'ac_lf_eyeball_ctrl'
        
        eye_center_position = mc.xform( eye_center , q=True , ws=True , t = True )
        
        #mc.parent(eyeuplid_ctrl, eyelowerlid_ctrl, eyeball_ctrl, eye_all_ctrl)
        zeroGrp_all = []
        for ctrl in [ eyeball_ctrl, eye_all_ctrl]:
            self.createTransformer( locName = ctrl ,position = eye_center_position , rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
            
            zerogrp = self.makeZeroGrpTwo( OrgObj = [ctrl],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)
            self.makeZeroGrpTwo( OrgObj = [ctrl],sufname='_offset',cenObj='',Mode=0,type = 'group',ro =True)
            
            zeroGrp_all.append(zerogrp[0])
        
        
        position_upperlid = mc.xform(uplidTem[1],q=True,ws=True,t=True)
        position_lowerlid = mc.xform(lowerlidTem[1],q=True,ws=True,t=True)
        #mc.move( 0 , 1, 4.5 , zeroGrp_all[1],r = True)
        #mc.move( 0 , -1, 1.5 , zeroGrp_all[2],r = True)
        #
        zero_upperlid = self.create_secondry_grp( ctrl_name = eyeuplid_ctrl ,position = position_upperlid ,IfInverse = 0 )
        zero_lowerlid = self.create_secondry_grp( ctrl_name = eyelowerlid_ctrl ,position = position_lowerlid ,IfInverse = 0 )
    '''
    ##===========================================================================================================================
    
    def eye_mirrorLocator(self,mirrorSection = 1 ,centorLoc = '' , orgPre ='lf_',tarPre = 'rt_' ,inputLoctors = ['ac_lf_innerlid_temloc','ac_lf_upperlid1_temloc','ac_lf_upperlid2_temloc','ac_lf_upperlid3_temloc','ac_lf_outerlid_temloc','ac_lf_lowerlid3_temloc','ac_lf_lowerlid2_temloc','ac_lf_lowerlid1_temloc','ac_lf_eyecrunch_temloc','ac_lf_innersocket_temloc','ac_lf_uppersocket1_temloc','ac_lf_uppersocket2_temloc','ac_lf_uppersocket3_temloc','ac_lf_outersocket_temloc','ac_lf_lowersocket3_temloc','ac_lf_lowersocket2_temloc','ac_lf_lowersocket1_temloc','ac_lf_eye_temloc']):
        
        rt_locators = []
        
        if centorLoc != '' :
            positionCentor = mc.xform( centorLoc , q=True ,ws=True,t=True  )
        else:
            positionCentor = (0,0,0)
        for ilocator in inputLoctors:

            rt_loc = str(ilocator).replace(orgPre , tarPre )
            rt_locators.append(rt_loc)

            if mirrorSection == 1: #   lf  to rt

                postion = mc.xform( ilocator , q=True , t=True , ws = True )
                
                positionXDis = positionCentor[0]*2 - postion[0]
                positionYDis = postion[1]
                positionZDis = postion[2]
                
                mc.xform( rt_loc , ws =True ,t =(positionXDis,positionYDis,positionZDis)  )
                
            else:
                postion = mc.xform( rt_loc , q=True , t=True , ws = True )
                
                positionXDis = positionCentor[0]*2 - postion[0]
                positionYDis = postion[1]
                positionZDis = postion[2]
                
                mc.xform( ilocator , ws =True ,t =(positionXDis,positionYDis,positionZDis)  )
                
            

    
    #============================================================================================================================
    
    def create_eye_settings(self ,ifMirror = 1, prefix = '', uplidTem = ['',''] ,lowerlidTem =['',''] , socketTem =['',''],inn_conner = '',out_conner ='' ,eye_center = '',eyectrl = 'ac_lf_eye_ctrl',uplidctrl = 'ac_lf_upperlid_ctrl',lowerlidectrl = 'ac_lf_lowerlid_ctrl',eyeballctrl = 'ac_lf_eyeball_ctrl',inputMesh = 'head_geo' ,eyecrunch = '' ):
        
        #==================================================================================
        #----- create curve --------------------------------------------------------------
        centerTem = eye_center
        logo_part = []
        for mo in range(len(centerTem)-7):
            logo_part.append( centerTem[mo] )
        logo = ''.join( logo_part )
        
        
        parentHeadGrp = prefix+ logo+'_parentHead'
        donottoutchGrp = prefix+ logo+'_donottoutch'
        parentStretchGrp = prefix+ logo+'_parentStretch'
        
        if mc.objExists( parentHeadGrp ) ==0:
            mc.group(em=True, n = parentHeadGrp )
        
        if mc.objExists( donottoutchGrp ) ==0:
            mc.group(em=True, n = donottoutchGrp )
            
        if mc.objExists( parentStretchGrp ) ==0:
            mc.group(em=True, n = parentStretchGrp )
        
        #------------------   socket 
        curveSocket = str(eye_center).replace('_temloc','_socket_curve')

        mc.circle( ch =False , nr =(0,1,0) , sections = 8 ,n = curveSocket )
        
        mc.parent( curveSocket , donottoutchGrp )
        
        num = 0
        
        for skt in socketTem:
            
            positon = mc.xform( skt ,q=True ,ws=True,t=True)
            mc.xform( str(curveSocket)+'.ep[' + str(num) +']' , t = positon , ws = True )
            num=num+1
            
            
        num = 0 
        for skt in socketTem:
            if num<7:
                cvNum = num+1
            else:
                cvNum = 0
            positon = mc.xform( skt ,q=True ,ws=True,t=True)
            clusterHand = str(skt).replace('_temloc','_influenceCL')
            clusterNode = str(skt).replace('_temloc','_cluster')
            
            #mc.xform( str(curveSocket)+'.ep[' + str(num) +']' , t = positon , ws = True )
            clusterInfo = mc.cluster( str(curveSocket)+'.cv[' + str(cvNum) +']'  )

            mc.rename( clusterInfo[0] , clusterNode )
            mc.rename( clusterInfo[1] , clusterHand )
            
            clusterHandleGrp = str(clusterHand)+'_zero'
            mc.group(clusterHand,n = clusterHandleGrp )
            
            eyesocket_ctrl = str(skt).replace('_temloc','_ctrl')
           
            if ifMirror==1:
                ifInv = 1
            else:
                ifInv = 0
                
            ctrl_zerogrp = self.create_secondry_grp( ctrl_name = eyesocket_ctrl ,position = positon ,IfInverse = ifInv )
                
            self.creatControls_command( type = 14 ,curName= eyesocket_ctrl ,add=True)
            self.scaleCurveHull( eyesocket_ctrl,0.3,0.3,0.3)
            self.lockAttr( obj = eyesocket_ctrl ,attr =['rx' ,'ry' ,'rz' ,'sx','sy','sz' ,'v' ])
            
            if ifMirror==1:
                Inv_X = -1
            else:
                Inv_X = 1
            
            self.LZ_connectAttr( outputObj = eyesocket_ctrl ,inputObj = clusterHand ,attribute = '.translate',inverseX = Inv_X ,inverseY = 1,inverseZ = 1)

            num = num+1
            
            mc.parent( clusterHandleGrp , donottoutchGrp)
            mc.parent( ctrl_zerogrp , parentHeadGrp )
            
       
        #-----------------------------------  eyelid -------------------------
        uplid_tem = [inn_conner]+ uplidTem +[out_conner]
        lowerlid_tem = [inn_conner]+ lowerlidTem +[out_conner]
        
        
        lf_uplid_wire_curve = ''
        lf_lowerlide_wire_curve = ''
        #for mont in range(len(uplid_tem)):
            
        lid_layar = 0
        for lid_tem  in [uplid_tem,lowerlid_tem]:
            position_all =[]
            
            for lt in lid_tem:
                position = mc.xform(lt ,q=True,ws=True,t=True)
                position_all.append(position)
                
            mc.curve(n = 'temple_ep_curve' ,ep = position_all )
            
            degree = mc.getAttr('temple_ep_curve.degree')
            spans =  mc.getAttr('temple_ep_curve.spans')
            
            position_cv_all = []
            for mn in range( degree+spans):
                if mn ==1  or mn == degree+spans - 2:
                    pass
                else:
                    position_cv = mc.xform('temple_ep_curve.cv['+ str(mn) + ']' ,q=True ,t=True ,ws=True )
                    position_cv_all.append(position_cv)
            if lid_layar==0:
                curvenam = prefix + logo + 'eyeupperlid_wire_curve'
                lf_uplid_wire_curve = curvenam
            else:
                curvenam = prefix + logo + '_eyelowerlid_wire_curve'
                lf_lowerlide_wire_curve = curvenam

            mc.curve( n = curvenam , p = position_cv_all ,k = ( 0 , 0 , 0 , 1 , 2 , 2 , 2))
            
            mc.parent( curvenam , donottoutchGrp )
            mc.delete( 'temple_ep_curve' )
            
            lid_layar = lid_layar+1
             
        ###---------------------------------   link cluster eyelids  --------------- 
        for mont in range(len(uplid_tem)):
            if mont ==0 or mont == len(uplid_tem)-1:
                clusterNode = str(uplid_tem[mont]).replace('_temloc' , '_cluster' ) 
                clusterHandle = str(uplid_tem[mont]).replace('_temloc' , '_influenceCL' )
                
                clusterInfo = mc.cluster( str(lf_uplid_wire_curve)+'.cv['+str(mont)+']', str(lf_lowerlide_wire_curve)+'.cv['+str(mont)+']' )
                
                mc.rename( clusterInfo[0] , clusterNode )
                mc.rename( clusterInfo[1] , clusterHandle )
                
                clusterGrp = str(clusterHandle)+'_zero'
                mc.group(clusterHandle ,n= clusterGrp)
                
                
                ctrl = str(uplid_tem[mont]).replace('_temloc' , '_ctrl' ) 
                position = mc.xform(uplid_tem[mont] ,q=True,ws=True,t=True)
                
                if ifMirror==1:
                    IfInv = 1
                else:
                    IfInv = 0
                
                ctrlzero = self.create_secondry_grp( ctrl_name = ctrl ,position = position ,IfInverse = IfInv )
                self.creatControls_command( type = 14 ,curName= ctrl ,add=True)
                self.scaleCurveHull( ctrl,0.3,0.3,0.3)
                
                self.lockAttr( obj = ctrl ,attr =['rx' ,'ry' ,'rz' ,'sx','sy','sz' ,'v' ])
                
                if ifMirror==1:
                    Inv_X = -1
                else:
                    Inv_X = 1
                
                self.LZ_connectAttr( outputObj = ctrl ,inputObj = clusterHandle ,attribute = '.translate',inverseX = Inv_X ,inverseY = 1,inverseZ = 1)
                
                
                mc.parent( ctrlzero , parentHeadGrp )
                mc.parent( clusterGrp ,donottoutchGrp)
            else:
                upperlid_clusterNode = str(uplid_tem[mont]).replace('_temloc' , '_cluster' ) 
                lowerlid_clusterNode = str(lowerlid_tem[mont]).replace('_temloc' , '_cluster' ) 
                #
                upperlid_clusterHandle = str(uplid_tem[mont]).replace('_temloc' , '_influenceCL' ) 
                lowerlid_clusterHandle = str(lowerlid_tem[mont]).replace('_temloc' , '_influenceCL' ) 
                ###
                upper_clusterInfo = mc.cluster( str(lf_uplid_wire_curve)+'.cv['+str(mont)+']' )
                lower_clusterInfo = mc.cluster( str(lf_lowerlide_wire_curve)+'.cv['+str(mont)+']' )
                ###
                mc.rename( upper_clusterInfo[0] , upperlid_clusterNode )
                mc.rename( upper_clusterInfo[1] , upperlid_clusterHandle )
                #
                mc.rename( lower_clusterInfo[0] , lowerlid_clusterNode )
                mc.rename( lower_clusterInfo[1] , lowerlid_clusterHandle )
                ###
                upper_clusterGrp = str(upperlid_clusterHandle)+'_zero'
                mc.group(upperlid_clusterHandle ,n= upper_clusterGrp)
                #
                lower_clusterGrp = str(lowerlid_clusterHandle)+'_zero'
                mc.group(lowerlid_clusterHandle ,n= lower_clusterGrp)
                ###
                upper_ctrl = str(uplid_tem[mont]).replace('_temloc' , '_ctrl' ) 
                upper_position = mc.xform(uplid_tem[mont] ,q=True,ws=True,t=True)
                
                
                if ifMirror==1:
                    IfInv = 1
                else:
                    IfInv = 0
                
                upper_ctrlzero = self.create_secondry_grp( ctrl_name = upper_ctrl ,position = upper_position ,IfInverse = IfInv )
                
                self.creatControls_command( type = 14 ,curName= upper_ctrl ,add=True)
                self.scaleCurveHull( upper_ctrl,0.3,0.3,0.3)
                
                self.lockAttr( obj = upper_ctrl ,attr =['rx' ,'ry' ,'rz' ,'sx','sy','sz' ,'v' ])
                
                if ifMirror==1:
                    Inv_X = -1
                else:
                    Inv_X = 1
                
                self.LZ_connectAttr( outputObj = upper_ctrl ,inputObj = upperlid_clusterHandle ,attribute = '.translate',inverseX = Inv_X,inverseY = 1,inverseZ = 1)
                #
                lower_ctrl = str(lowerlid_tem[mont]).replace('_temloc' , '_ctrl' ) 
                lower_position = mc.xform(lowerlid_tem[mont] ,q=True,ws=True,t=True)
                
                if ifMirror==1:
                    IfInv = 1
                else:
                    IfInv = 0
                
                lower_ctrlzero = self.create_secondry_grp( ctrl_name = lower_ctrl ,position = lower_position ,IfInverse = IfInv )
                
                self.creatControls_command( type = 14 ,curName= lower_ctrl ,add=True)
                self.scaleCurveHull( lower_ctrl,0.3,0.3,0.3)
                
                self.lockAttr( obj = lower_ctrl ,attr =['rx' ,'ry' ,'rz' ,'sx','sy','sz' ,'v' ])
                
                if ifMirror==1:
                    Inv_X = -1
                else:
                    Inv_X = 1
                
                
                self.LZ_connectAttr( outputObj = lower_ctrl ,inputObj = lowerlid_clusterHandle ,attribute = '.translate',inverseX = Inv_X ,inverseY = 1,inverseZ = 1)
                
                
                
                mc.parent( lower_ctrlzero ,upper_ctrlzero , parentHeadGrp )
                mc.parent( lower_clusterGrp ,upper_clusterGrp ,donottoutchGrp)
        
        eyecrunch_ctrl = str(eyecrunch).replace('_temloc','_ctrl')
        position_eyeCrunch = mc.xform(eyecrunch,q=True,t=True,ws=True )
        if ifMirror==1:
            IfInv = 1
        else:
            IfInv = 0
        zero_crunch_Grp =self.create_secondry_grp( ctrl_name = eyecrunch_ctrl ,position = position_eyeCrunch ,IfInverse = IfInv )
        
        self.creatControls_command( type = 2 ,curName= eyecrunch_ctrl ,add=True)
        self.scaleCurveHull( eyecrunch_ctrl,0.8,0.5,0.6)
        
        self.lockAttr( obj = eyecrunch_ctrl ,attr =['tx' , 'tz' ,'rx' ,'ry' ,'rz' ,'sx','sy','sz' ,'v' ])
        mc.transformLimits( eyecrunch_ctrl , ty = (-1,1), ety = (1,1) ) 
        
        mc.parent(  zero_crunch_Grp, parentHeadGrp )
        '''
        #=========================================================
        #||                                                     ||
        #||             eye ball                                ||
        #||                                                     ||
        #||                                                     ||
        #=========================================================
        
        '''         
        
        
        eye_all_ctrl = eyectrl
        eyeuplid_ctrl =  uplidctrl
        eyelowerlid_ctrl = lowerlidectrl
        eyeball_ctrl = eyeballctrl
        
        eye_center_position = mc.xform( eye_center , q=True , ws=True , t = True )
        
        
        position_upperlid = mc.xform(uplidTem[1],q=True,ws=True,t=True)
        position_lowerlid = mc.xform(lowerlidTem[1],q=True,ws=True,t=True)
        #print(lowerlidTem[1])
        #mc.parent(eyeuplid_ctrl, eyelowerlid_ctrl, eyeball_ctrl, eye_all_ctrl)
        zeroGrp_all = []
        skinJnts = []
        offsetGrps = []
        followBasegrp = [] 
        conGrps = []
        
        followJnt = []
        followGrp = []
        rotateGrps=[]
        num = 0
        for ctrl in [ eyeball_ctrl , eye_all_ctrl]:
            self.createTransformer( locName = ctrl ,position = eye_center_position , rotation = ( 0,0,0) ,type = 'group',LocPosion = (0,0,0))
            
            #if ifMirror==1:
            ##   mc.setAttr(str(ctrl)+'.jointOrientX' , -180 )
            #    if ctrl == eye_all_ctrl
            
            jnt = str(ctrl).replace('_ctrl','_jnt')
            self.createTransformer( locName = jnt ,position = eye_center_position , rotation = ( 0,0,0) ,type = 'joint',LocPosion = (0,0,0))
            jntZero = self.makeZeroGrpTwo( OrgObj = [jnt],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)
            
            zerogrp = self.makeZeroGrpTwo( OrgObj = [ctrl],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)
            self.makeZeroGrpTwo( OrgObj = [ctrl],sufname='_offset',cenObj='',Mode=0,type = 'group',ro =True)
            
            
            ######
            
            
            if ifMirror==1 and num == 1:
                #mc.setAttr( str( zeroGrp_all[0] )+'.scaleZ' , -1 )
                #mc.setAttr( str( zeroGrp_all[0] )+'.rotateY' , 180 )
                mc.setAttr( str( zerogrp[0])+'.scaleX' , -1 )
            
                
            if num == 0 :
                
                
                mc.addAttr( ctrl,  ln = 'lids_follow_eye' , k = True, dv =1 ,min = 0 , max = 1)
                mc.addAttr( ctrl,  ln = 'pupil_size' , k = True, dv =1 ,min = 0.1, max = 2)
                mc.addAttr( ctrl,  ln = 'iris_size' , k = True, dv =1 ,min = 0.1 , max = 2)
                
                
                shapetype = 20
                
                mc.parent( jntZero , parentHeadGrp )
                
                upperlide_followBase = str(uplidctrl).replace('_ctrl','_follow_base')
                upperlide_jnt = str(uplidctrl).replace('_ctrl','_follow_jnt')
                
                lowerlide_followBase  = str(lowerlidectrl).replace('_ctrl','_follow_base')
                lowerlide_jnt = str(lowerlidectrl).replace('_ctrl','_follow_jnt')
                
                
                self.createSeketon( seketonInfo = [ (upperlide_followBase , eye_center_position ),(upperlide_jnt , position_upperlid )] ,selectCancle = 1 )
                

                self.createSeketon( seketonInfo = [ (lowerlide_followBase , eye_center_position ),(lowerlide_jnt , position_lowerlid )] ,selectCancle = 1 )
                
                #print((lowerlide_jnt , position_lowerlid ))
                
                followBasegrp.append(upperlide_followBase)
                followBasegrp.append(lowerlide_followBase)
                #self.createTransformer( locName = upperlide_jnt ,position = eye_center_position , rotation = ( 0,0,0) ,type = 'joint',LocPosion = (0,0,0))
                #self.createTransformer( locName = lowerlide_jnt ,position = eye_center_position , rotation = ( 0,0,0) ,type = 'joint',LocPosion = (0,0,0))
                
                upperlidOffset = self.makeZeroGrpTwo( OrgObj = [upperlide_followBase],sufname='_follow_grp',cenObj = jnt ,Mode=0,type = 'group',ro =True)
                mc.addAttr( upperlidOffset[0] , ln = 'follow' , k = True )
                
                mc.connectAttr( str(ctrl)+'.lids_follow_eye' , str(upperlidOffset[0] ) + '.follow' )
                
                
                upperlid_Zero = self.makeZeroGrpTwo( OrgObj = [upperlide_followBase],sufname='_follow_con_zero',cenObj = jnt ,Mode=0,type = 'group',ro =True)
                follow_con = self.makeZeroGrpTwo( OrgObj = [upperlide_followBase],sufname='_follow_con',cenObj = jnt ,Mode=0,type = 'group',ro =True)
                upperlid_ConZero = self.makeZeroGrpTwo( OrgObj = [upperlide_followBase],sufname='_con_zero',cenObj = '' ,Mode=0,type = 'group',ro =True)
                con_grp = self.makeZeroGrpTwo( OrgObj = [upperlide_followBase],sufname='_con',cenObj = '' ,Mode=0,type = 'group',ro =True)
                
                
                conGrps.append(con_grp[0])
                mc.connectAttr(str(upperlidOffset[0])+'.rotate',str(follow_con[0])+'.rotate')
                
                lowerlidOffset = self.makeZeroGrpTwo( OrgObj = [lowerlide_followBase],sufname='_follow_grp',cenObj = jnt ,Mode=0,type = 'group',ro =True)
                mc.addAttr( lowerlidOffset[0] , ln = 'follow' , k = True )
                mc.connectAttr( str(ctrl)+'.lids_follow_eye' , str(lowerlidOffset[0] ) + '.follow' )
                
                
                lowerlid_Zero = self.makeZeroGrpTwo( OrgObj = [lowerlide_followBase],sufname='_follow_con_zero',cenObj = jnt ,Mode=0,type = 'group',ro =True)
                follow_con = self.makeZeroGrpTwo( OrgObj = [lowerlide_followBase],sufname='_follow_con',cenObj = jnt ,Mode=0,type = 'group',ro =True)
                lowerlid_ConZero = self.makeZeroGrpTwo( OrgObj = [lowerlide_followBase],sufname='_con_zero',cenObj = '' ,Mode=0,type = 'group',ro =True)
                con_grp = self.makeZeroGrpTwo( OrgObj = [lowerlide_followBase],sufname='_con',cenObj = '' ,Mode=0,type = 'group',ro =True)
                
                
                conGrps.append(con_grp[0])
                mc.connectAttr(str(lowerlidOffset[0])+'.rotate',str(follow_con[0])+'.rotate')
                ## 
                baseJnt = str(uplidctrl).replace('_ctrl','_followBase_jnt')
                self.createTransformer( locName = baseJnt ,position = eye_center_position , rotation = ( 0,0,0) ,type = 'joint',LocPosion = (0,0,0))
                
                mc.parent(upperlidOffset , lowerlidOffset , upperlid_Zero,lowerlid_Zero,jnt ,baseJnt )
                baseZero = self.makeZeroGrpTwo( OrgObj = [baseJnt],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)
                
                
                
                ######
                constrintNode = str(uplidctrl).replace('_ctrl','_follow_parentConstraint')
                mc.parentConstraint(  baseJnt , jnt ,upperlidOffset ,mo=True , n = constrintNode )
                
                self.LZ_setDrivenKey( str(upperlidOffset[0])+'.follow',str(constrintNode) + '.'+str(baseJnt) + 'W0',0,1)
                self.LZ_setDrivenKey( str(upperlidOffset[0])+'.follow',str(constrintNode) + '.'+str(baseJnt) + 'W0',1,1)
                
                self.LZ_setDrivenKey( str(upperlidOffset[0])+'.follow',str(constrintNode) + '.'+str(jnt) + 'W1',0,0)
                self.LZ_setDrivenKey( str(upperlidOffset[0])+'.follow',str(constrintNode) + '.'+str(jnt) + 'W1',1,1)
                
                ain_node01 = self.findNode_animation( driver = str(upperlidOffset[0])+'.follow' , driven = str(constrintNode) + '.'+str(jnt) + 'W1' )
                self.list_keytangent_type( animCurve = ain_node01 , type='linear')
                
                ain_node02 = self.findNode_animation( driver = str(upperlidOffset[0])+'.follow' , driven = str(constrintNode) + '.'+str(baseJnt) + 'W0' )
                self.list_keytangent_type( animCurve = ain_node02 , type='linear')
                
                ####
                constrintNode = str(lowerlidectrl).replace('_ctrl','_follow_parentConstraint')
                mc.parentConstraint(  baseJnt , jnt ,lowerlidOffset ,mo=True , n = constrintNode )
                
                self.LZ_setDrivenKey( str(lowerlidOffset[0])+'.follow',str(constrintNode) + '.'+str(baseJnt) + 'W0',0,1)
                self.LZ_setDrivenKey( str(lowerlidOffset[0])+'.follow',str(constrintNode) + '.'+str(baseJnt) + 'W0',1,1)
                
                self.LZ_setDrivenKey( str(lowerlidOffset[0])+'.follow',str(constrintNode) + '.'+str(jnt) + 'W1',0,0)
                self.LZ_setDrivenKey( str(lowerlidOffset[0])+'.follow',str(constrintNode) + '.'+str(jnt) + 'W1',1,1)
                
                ain_node01 = self.findNode_animation( driver = str(lowerlidOffset[0])+'.follow' , driven = str(constrintNode) + '.'+str(jnt) + 'W1' )
                self.list_keytangent_type( animCurve = ain_node01 , type='linear')
                
                ain_node02 = self.findNode_animation( driver = str(lowerlidOffset[0])+'.follow' , driven = str(constrintNode) + '.'+str(baseJnt) + 'W0' )
                self.list_keytangent_type( animCurve = ain_node02 , type='linear')
                ##-----------------------

                eyeAimLoc = str(jnt).replace('_jnt','_aimLoc')
                
                self.createTransformer( locName = eyeAimLoc ,position = eye_center_position , rotation = ( 0,0,0) ,type = 'joint',LocPosion = (0,0,0))
                mc.parent( eyeAimLoc , ctrl )
                
                if ifMirror==1:
                    tranZ = 5
                else:
                    
                    tranZ = 5
                    
                mc.setAttr( str(eyeAimLoc) +'.translateZ' , tranZ )
                #aimConstraint -offset 0 0 0 -weight 1 -aimVector 0 0 1 -upVector 0 1 0 -worldUpType "objectrotation" -worldUpVector 0 1 0 -worldUpObject ac_lf_upperlid_followBase_jnt
                mc.aimConstraint( eyeAimLoc , jnt , aimVector = (0,0,1) , worldUpType = 'objectrotation' , worldUpVector= (0,1,0) , worldUpObject =  baseJnt)
                
                followGrp.append(upperlidOffset)
                followGrp.append(lowerlidOffset)
                
                
                followJnt.append( baseJnt )
                followJnt.append( upperlide_jnt )
                followJnt.append( lowerlide_jnt )
                
                poivet = [baseJnt,upperlide_followBase,lowerlide_followBase]
                jntsP = [baseJnt , upperlide_jnt , lowerlide_jnt ]
                
                inverseJnts = []
                for num_ij in range(3):
                    inverseJnt = str(jntsP[num_ij])+'_reverse'
                    self.LZ_creatJoint( jntsP[num_ij],inverseJnt)
                    inverseJnts.append(inverseJnt)
                    
                mc.parent( inverseJnts[1],inverseJnts[2],inverseJnts[0])
                
                inverseCons = []
                zeroInverse = []
                for num_ijnt in range(3):
                    zero = self.makeZeroGrpTwo( OrgObj = [ inverseJnts[num_ijnt] ],sufname='_zero',cenObj = poivet[num_ijnt] ,Mode=0,type = 'group',ro =True)
                    conInverse = self.makeZeroGrpTwo( OrgObj = [ inverseJnts[num_ijnt]  ],sufname='_con',cenObj = poivet[num_ijnt]  ,Mode=0,type = 'group',ro =True)
                    inverseCons.append(conInverse[0])
                    zeroInverse.append(zero[0])
                    
                    
                #mc.connectAttr(str(upperlidOffset[0])+'.rotate' , str(inverseCons[1])+'.rotate' )
                #mc.connectAttr(str(lowerlidOffset[0])+'.rotate' , str(inverseCons[2])+'.rotate' )
                '''     2015 / 03 / 18 modify
                mc.parentConstraint( baseJnt , inverseCons[0] ,mo=True  )
                '''
                mc.parent( zeroInverse[0] , donottoutchGrp )
                
            
            else:
            
                shapetype = 5
                skinJnts.append( jnt )
                mc.parent( jntZero , donottoutchGrp )
                
                
                upperlide_rotate = str(uplidctrl).replace('_ctrl','_rotatejnt')
                upperlide_jnt = str(uplidctrl).replace('_ctrl','_jnt')
                
                lowerlide_rotate  = str(lowerlidectrl).replace('_ctrl','_rotatejnt')
                lowerlide_jnt = str(lowerlidectrl).replace('_ctrl','_jnt')
                
                
                self.createSeketon( seketonInfo = [ (upperlide_rotate , eye_center_position ) ,(upperlide_jnt , position_upperlid )] ,selectCancle = 1 )
                

                self.createSeketon( seketonInfo = [ (lowerlide_rotate , eye_center_position ) ,(lowerlide_jnt , position_lowerlid )] ,selectCancle = 1 )
                upperlidOffset = self.makeZeroGrpTwo( OrgObj = [upperlide_jnt],sufname='_offset',cenObj = upperlide_rotate ,Mode=0,type = 'group',ro =True)
                lowerlidOffset = self.makeZeroGrpTwo( OrgObj = [lowerlide_jnt],sufname='_offset',cenObj = lowerlide_rotate ,Mode=0,type = 'group',ro =True)
                
                upperlid_rotate = self.makeZeroGrpTwo( OrgObj = [upperlide_jnt],sufname='_rotate',cenObj = upperlide_rotate ,Mode=0,type = 'group',ro =True)
                lowerlid_rotate = self.makeZeroGrpTwo( OrgObj = [lowerlide_jnt],sufname='_rotate',cenObj = lowerlide_rotate ,Mode=0,type = 'group',ro =True)
                
                mc.parent(upperlide_rotate , jnt)
                mc.parent(lowerlide_rotate , jnt)
                
                skinJnts.append(upperlide_jnt)
                skinJnts.append(lowerlide_jnt)
                
                offsetGrps.append( upperlidOffset[0])
                offsetGrps.append( lowerlidOffset[0])
                
                rotateGrps.append(upperlid_rotate[0] )
                rotateGrps.append( lowerlid_rotate[0])
                
                mc.parent( baseZero , ctrl)
                
            self.creatControls_command( type = shapetype ,curName= ctrl ,add=True)
            ############
            self.lockAttr( obj = eyecrunch_ctrl ,attr =['tx' , 'tz' ,'rx' ,'ry' ,'sx','sy','sz' ,'v' ])
            
            if ifMirror==1:
                transZ = 4.5
            else:
                transZ = 4.5
            
            if num == 1:
            
                self.rotateCurveHull(  curveName = ctrl,rx = 90,ry = 0, rz = 0 ,centerP = 1 )
                self.moveCurveHull(  curveName = ctrl ,tx = 0,ty = 0, tz = transZ )
                self.scaleCurveHull(ctrl,2,2,2)
            
            zeroGrp_all.append(zerogrp[0])
            
            if num == 0:
                self.lockAttr( obj = ctrl ,attr =[ 'tx' ,'ty','tz','v' ])
            else:
                self.lockAttr( obj = ctrl ,attr =['v' ])
            
            num = num + 1
            
        #offsetGrps    followJnt
        inverse_All = [inverseCons[1],inverseCons[2]]
        
        for i in range(2):
            #
            #print(conGrps)
            
            mc.connectAttr(str(offsetGrps[i]) + '.rotate',str(conGrps[i] + '.rotate'))
            #mc.connectAttr(str(upperlidOffset[0])+'.rotate' , str(inverseCons[1])+'.rotate' )
            #mc.connectAttr(str(lowerlidOffset[0])+'.rotate' , str(inverseCons[2])+'.rotate' )
            mc.connectAttr(str(offsetGrps[i]) + '.rotate',str(inverse_All[i] + '.rotate'))
            
            #self.createTransformer( locName = ctrl ,position = eye_center_position , rotation = ( 0,0,0) ,type = 'group',LocPosion = (0,0,0))
        
        

        mc.parent( zeroGrp_all[0] ,eye_all_ctrl )
        mc.parent( zeroGrp_all[1] , parentStretchGrp)
        #self.createSeketon( seketonInfo = [ ('lowerlide_followBase' , eye_center_position ),('lowerlide_jnt' , position_lowerlid )] ,selectCancle = 1 )
        #print zeroGrp_all
        ####if ifMirror==1:
        ####    mc.setAttr( str( zeroGrp_all[0] )+'.scaleZ' , -1 )
        ####    mc.setAttr( str( zeroGrp_all[0] )+'.rotateY' , 180 )
        ####    mc.setAttr( str( zeroGrp_all[1] )+'.scaleX' , -1 )
        

        
        
        #mc.move( 0 , 1, 4.5 , zeroGrp_all[1],r = True)
        #mc.move( 0 , -1, 1.5 , zeroGrp_all[2],r = True)
        
        
        
        #
        
        if ifMirror==1:
            IfInv = 1
        else:
            IfInv = 0
        zero_upperlid = self.create_secondry_grp( ctrl_name = eyeuplid_ctrl ,position = position_upperlid ,IfInverse = IfInv )
        zero_lowerlid = self.create_secondry_grp( ctrl_name = eyelowerlid_ctrl ,position = position_lowerlid ,IfInverse = IfInv )
        
        self.creatControls_command( type = 19 ,curName= eyeuplid_ctrl ,add=True)
        self.creatControls_command( type = 19 ,curName= eyelowerlid_ctrl ,add=True)
        
        #if ifMirror==1:
        #    Inv_X = -1
        #else:
        #    Inv_X = 1
        self.moveCurveHull(  curveName = eyeuplid_ctrl ,tx = 0,ty = 0, tz = 0.5 )
        self.moveCurveHull(  curveName = eyelowerlid_ctrl ,tx = 0,ty = 0, tz = 0.5 )
        
        self.rotateCurveHull(  curveName = eyeuplid_ctrl,rx = 90,ry = 0, rz = 0 ,centerP = 0 )
        self.rotateCurveHull(  curveName = eyelowerlid_ctrl,rx = -90,ry = 0, rz = 0 ,centerP = 0 )
        
        self.moveCurveHull(  curveName = eyeuplid_ctrl ,tx = 0,ty = 0, tz = 0.5 )
        self.moveCurveHull(  curveName = eyelowerlid_ctrl ,tx = 0,ty = 0, tz = 0.5 )
        
        
        mc.parent( zero_upperlid ,zero_lowerlid, parentHeadGrp )
        
        self.lockAttr( obj = eyeuplid_ctrl ,attr =['tx' , 'tz' ,'rx' ,'ry'  ,'sx','sy','sz' ,'v' ])
        mc.transformLimits( eyeuplid_ctrl , ty = (-2,1), ety = (1,1) ) 
        
        self.lockAttr( obj = eyelowerlid_ctrl ,attr =['tx' , 'tz' ,'rx' ,'ry'  ,'sx','sy','sz' ,'v' ])
        mc.transformLimits( eyelowerlid_ctrl , ty = (-1,2), ety = (1,1) ) 
        
        
        
        if ifMirror==1:
            ives = -1
        else:
            ives = 1
        
        self.LZ_connectAttr_02( outputObj = eyeuplid_ctrl ,inputObj = rotateGrps[0] ,outputattribute = ['.rotateZ','',''],inputattribute = ['.rotateX','',''],inverseX = ives,inverseY = 1,inverseZ = ives)
        self.LZ_connectAttr_02( outputObj = eyelowerlid_ctrl ,inputObj = rotateGrps[1] ,outputattribute = ['.rotateZ','',''],inputattribute = ['.rotateX','',''],inverseX = ives,inverseY = 1,inverseZ = ives)
        
        
        follow_joints = []
        for  fj in followJnt:
            if '_jnt' in fj:
                follow_joints.append(fj)
        
        return [ offsetGrps, skinJnts ,[lf_uplid_wire_curve,lf_lowerlide_wire_curve,curveSocket] ,[ parentHeadGrp , donottoutchGrp , parentStretchGrp ] ,followGrp ,follow_joints ]
        
        ###=================================================================================================
        #self.conneReverseAttr_singgle( inputJnt = '' ,revertJnt = '', skinname = ''  )             inputMesh
        
        #for eye_Ctrl in [eye_all_ctrl ,eyeuplid_ctrl ,eyelowerlid_ctrl ,eyeball_ctrl ]:
        '''
        upperlide_rotate_ik = str(uplidctrl).replace('_ctrl','_ikjnt')
        upperlide_rotate_ikend = str(uplidctrl).replace('_ctrl','_ikjntend')
        
        lowerlide_rotate_ik = str(lowerlidectrl).replace('_ctrl','_ikjnt')
        lowerlide_rotate_ikend = str(lowerlidectrl).replace('_ctrl','_ikjntend')
        
        ikhandle_upper = str(upperlide_rotate_ik)+'_ikhadle'
        ikhandle_lower = str(lowerlide_rotate_ik)+'_ikhadle'
        
        print(uplidctrl,lowerlidectrl)
        self.createSeketon( seketonInfo = [ (upperlide_rotate_ik , eye_center_position ) ,(upperlide_rotate_ikend , position_upperlid )] ,selectCancle = 1 )
        self.createSeketon( seketonInfo = [ (lowerlide_rotate_ik , eye_center_position ) ,(lowerlide_rotate_ikend , position_lowerlid )] ,selectCancle = 1 )
        
        mc.ikHandle( sj = upperlide_rotate_ik , ee =upperlide_rotate_ikend  , n = ikhandle_upper )
        mc.ikHandle( sj = lowerlide_rotate_ik , ee =lowerlide_rotate_ikend , n = ikhandle_lower )
        
        ikhandle_zero = self.makeZeroGrpTwo( OrgObj = [ikhandle_upper,ikhandle_lower],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True)
        mc.parent( ikhandle_zero , parentHeadGrp )
        '''
        
        
        
    def createEye_crunchExpand_network(self , crunchCtrlAttr = 'xxx.aaa' ,upperlid_ctrlAttr = 'xxx.aaa' ,lowerlid_ctrlAttr = 'xxx.aaa' ,narmalValue = 1  ): 
        
        crunchCtrl = str(crunchCtrlAttr).split('.')[0]
        upperlid_ctrl = str(upperlid_ctrlAttr).split('.')[0]
        lowerlid_ctrl = str(lowerlid_ctrlAttr).split('.')[0]
        
        
        centerTem = crunchCtrl
        logo_part = []
        for mo in range(len(centerTem)-4):
            logo_part.append( centerTem[mo] )
        logo = ''.join( logo_part )
        

        bridgeGrp = logo + 'bridge'
        if mc.objExists(bridgeGrp) == 0:
            mc.group( em = True, n = bridgeGrp)
            addAttrs = [ 'crunch' ,'expand' , 'upperlid_close','lowerlid_close' , 'upperlid_open','lowerlid_open' ]
            
            for at in addAttrs:
                mc.addAttr( bridgeGrp , ln = at , k = True )
                
        ##========================================================================
        #----------------------- create pos and neg settings ------------------
        

        crunchctrl_output = self.create_clamp_posneg_network(  objAttr = crunchCtrlAttr ,normalValue = 1 )
        upperlid_output = self.create_clamp_posneg_network(  objAttr = upperlid_ctrlAttr ,normalValue = 1 )
        lowerlid_output = self.create_clamp_posneg_network(  objAttr = lowerlid_ctrlAttr ,normalValue = 1 )
        
        ##========================================================================
        #------------------------ link crunch and expand --------------
        mc.connectAttr( str(crunchctrl_output[0])+'.outputR' , str(bridgeGrp)+'.expand'  )
        mc.connectAttr( str(crunchctrl_output[1])+'.outputR' , str(bridgeGrp)+'.crunch'  )
        
        ##========================================================================
        #------------------------ link crunch and expand --------------
        
        ifCrunchMd = logo + 'crunch_narmal_md'
        ifExpandMd = logo + 'expand_narmal_md'
        
        mc.createNode( 'multiplyDivide', n = ifCrunchMd)
        mc.createNode( 'multiplyDivide', n = ifExpandMd)
        
        mc.connectAttr( str(crunchctrl_output[1])+'.outputR' , str(ifCrunchMd) +'.input1X')
        mc.connectAttr( str(crunchctrl_output[0])+'.outputR' , str(ifExpandMd) +'.input1X')
        
        '''
        #
        sumMPA = logo + 'crunch_sum_pma'
        mc.createNode( 'plusMinusAverage' , n =sumMPA )
        
        mc.connectAttr( str(ifCrunchMd) +'.outputX' , str(sumMPA) + '.input1D[0]' )
        mc.connectAttr( str(ifExpandMd) +'.outputX' , str(sumMPA) + '.input1D[1]' )
        
        
        #
        sumClamp = logo + 'crunch_sum_clamp'
        mc.createNode( 'clamp' , n = sumClamp  )
        
        mc.connectAttr( str(sumMPA) +'.output1D' , str(sumClamp) + '.inputR' )
        mc.setAttr( str(sumClamp) + '.maxR' ,1 )
        #
        sumReverse = logo + 'crunch_sum_reverse'
        mc.createNode( 'reverse' , n = sumReverse  )
        
        mc.connectAttr( str(sumClamp) + '.outputR', str(sumReverse) + '.input.inputX' )
        
        '''
        pma_node = [ 'upperlid_closed_sum_pma' , 'upperlid_open_sum_pma' , 'lowerlid_closed_sum_pma'  , 'lowerlid_open_sum_pma'   ]
        
        reverse_all = []
        for pma in pma_node:
            node_pma = logo + pma
            mc.createNode( 'plusMinusAverage' , n = node_pma )
            
            clamp = str(pma).replace('_sum_pma','_sum_clamp')
            sumClamp = logo + clamp
            mc.createNode( 'clamp' , n = sumClamp )
            mc.setAttr( str(sumClamp) + '.maxR' ,1 )
            
            reverse = str(pma).replace('_sum_pma','_sum_reverse')
            sumReverse = logo + reverse
            mc.createNode( 'reverse' , n = sumReverse  )
            
            mc.connectAttr( str(ifCrunchMd) +'.outputX' , str(node_pma) + '.input1D[0]' )
            mc.connectAttr( str(ifExpandMd) +'.outputX' , str(node_pma) + '.input1D[1]' )
            
            mc.connectAttr( str(node_pma) +'.output1D' , str(sumClamp) + '.inputR' )
            
            mc.connectAttr( str(sumClamp) + '.outputR', str(sumReverse) + '.input.inputX' )
        
            reverse_all.append(sumReverse)
        
        ##--------------------- create 4 nodes for upperlid and lowerlid -------------------
        
        upper_closed_md = logo + 'upperlid_closed_md'
        upper_open_md = logo + 'upperlid_open_md'
        lower_closed_md = logo + 'lowerlid_closed_md'
        lower_open_md = logo + 'lowerlid_open_md'
        '''
        for lid_md in [ upper_closed_md, upper_open_md , lower_closed_md , lower_open_md ]:
            mc.createNode( 'multiplyDivide' , n = lid_md )
            
            mc.connectAttr( str(sumReverse) + '.outputX' , str(lid_md)+'.input1X' )
        '''
        lid_md_all  = [ upper_closed_md, upper_open_md , lower_closed_md , lower_open_md ]
        for num in range(4):
            mc.createNode( 'multiplyDivide' , n = lid_md_all[num] )
            mc.connectAttr( str(reverse_all[num]) + '.outputX' , str(lid_md_all[num])+'.input1X' )
        
        ##---------------------------- link to bridge attributes -----------------------------
        #'upperlid_close','lowerlid_close' , 'upperlid_open','lowerlid_open'
        mc.connectAttr(  str(upper_closed_md)+'.outputX' , str( bridgeGrp )+'.upperlid_close' )
        mc.connectAttr(  str(lower_closed_md)+'.outputX' , str( bridgeGrp )+'.lowerlid_close' )
        mc.connectAttr(  str(upper_open_md)+'.outputX' , str( bridgeGrp )+'.upperlid_open' )
        mc.connectAttr(  str(lower_open_md)+'.outputX' , str( bridgeGrp )+'.lowerlid_open' )
        
        mc.connectAttr( str( upperlid_output[0] ) + '.outputR' ,str(upper_open_md) + '.input2X'  )
        mc.connectAttr( str( upperlid_output[1] ) + '.outputR' ,str(upper_closed_md) + '.input2X'  )
        
        mc.connectAttr( str( lowerlid_output[0] ) + '.outputR' ,str(lower_closed_md) + '.input2X'  )
        mc.connectAttr( str( lowerlid_output[1] ) + '.outputR' ,str(lower_open_md) + '.input2X'  )
        
        
        
        
        return [ bridgeGrp ]

        
    def create_clamp_posneg_network(self , objAttr = 'xxx.bbb',normalValue = 1 ):
        
        obj = str(objAttr).split('.')[0]
        
        normalMd = obj + '_normal_md'
        posClamp = obj + '_pos_clamp'
        negMd = obj + '_neg_md'
        negClamp = obj + '_neg_clamp'
        
        for clp in [ posClamp , negClamp ]:
            mc.createNode( 'clamp' ,n = clp )
            
        for md in [ normalMd, negMd]:
            mc.createNode( 'multiplyDivide' ,n = md )
            
        mc.connectAttr( objAttr ,  str(normalMd)+'.input1X' )
        mc.setAttr( str(normalMd)+'.input2X' , normalValue)

        
        
        mc.connectAttr( str(normalMd)+'.outputX' , str(posClamp)+'.inputR'  )
        mc.connectAttr( str(normalMd)+'.outputX' , str(negMd)+'.input1X'  )
        mc.connectAttr( str(negMd)+'.outputX' , str(negClamp)+'.inputR' )
        
        mc.setAttr( str(posClamp)+'.maxR' , 1 )
        mc.setAttr( str(negClamp)+'.maxR' , 1 )
        mc.setAttr( str(negMd)+'.input2X' , -1 )
    
        return  [posClamp,negClamp]
    
    '''
    def narmalize_eyeCtrl(self,ctrlAttr = 'xxx.bb',inverse = 0 ):
        ctrl = str(ctrlAttr).split('.')[0]
        pma = ctrl+'_attrNromal_freezen_pma'
        
        normal_md = ctrl+'_attrNromal_normal_md'
        
        pos_md = ctrl+'_attrNromal_pos_md'
        neg_md = ctrl+'_attrNromal_neg_md'
        pos_clamp = ctrl+'_attrNromal_pos_clamp'
        neg_clamp = ctrl+'_attrNromal_neg_clamp'
        
        conditionNode = ctrl+'_attrNromal_condition'
        
        
        
        
        if inverse == 0:
            inputPosMD = 0.5
            inputNegMD = 1
            pma_input= 1
        else:
            inputPosMD = 1
            inputNegMD = 0.5
            pma_input = -1
        
        mc.createNode( 'multiplyDivide', n = normal_md )
        mc.connectAttr(  ctrlAttr , str(normal_md) + '.input1X' )
        mc.setAttr( str(normal_md) + '.input2X' , 1 )
        
        mc.createNode( 'plusMinusAverage', n = pma )
        
        mc.connectAttr( str(normal_md) + '.outputX' , str(pma) + '.input2D[0].input2Dx' )
        mc.setAttr( str(pma) + '.input2D[1].input2Dx' , pma_input )
        
        
        mc.createNode( 'multiplyDivide', n = neg_md )
        mc.connectAttr(  str(pma) + '.output2Dx' , str(neg_md) + '.input1X' )
        mc.setAttr( str(neg_md) + '.input2X' , inputNegMD )
        
        mc.createNode( 'multiplyDivide', n = pos_md )
        mc.connectAttr(  str(pma) + '.output2Dx' , str(pos_md) + '.input1X' )
        mc.setAttr( str(pos_md) + '.input2X' , inputPosMD )
        
        
        
        mc.createNode( 'clamp', n = pos_clamp )
        
        mc.connectAttr(  str(pos_md) + '.outputX' , str(pos_clamp) + '.inputR' )
        mc.setAttr(  str(pos_clamp) + '.maxR'  ,1 )
        
        mc.createNode( 'clamp', n = neg_clamp )
        mc.setAttr(  str(neg_clamp) + '.minR'  ,-1 )
        mc.connectAttr(  str(neg_md) + '.outputX' , str(neg_clamp) + '.inputR' )
        
        bridge = ctrl+'_attr_normal_bridge'
        
        if mc.objExists(bridge) == 0:
            mc.group( em =True ,n = bridge )
        
        mc.addAttr(bridge , ln = 'pos_attr' ,k=True )
        mc.addAttr(bridge , ln = 'neg_attr' ,k=True  )
        mc.addAttr(bridge , ln = 'normalized_attr' ,k=True  )
        
        mc.connectAttr( str(neg_clamp)+ '.outputR' , str( bridge ) + '.neg_attr' )
        mc.connectAttr( str(pos_clamp)+ '.outputR' , str( bridge ) + '.pos_attr' )
        
        
        mc.createNode( 'condition', n = conditionNode )
        mc.connectAttr(  str(pma)+'.output2D.output2Dx', str(conditionNode) +'.firstTerm' )
        mc.connectAttr(  str(pos_clamp)+'.output.outputR', str(conditionNode) +'.colorIfTrueR' )
        mc.connectAttr(  str(neg_clamp)+'.output.outputR', str(conditionNode) +'.colorIfFalseR' )
        mc.setAttr(  str(conditionNode) +'.operation' , 2 )
        mc.connectAttr( str(conditionNode)+ '.outColorR' , str( bridge ) + '.normalized_attr' )
        
        return [ str( bridge ) + '.normalized_attr' , str( bridge ) + '.pos_attr' , str( bridge ) + '.neg_attr']
    '''
        
    def narmalize_eyeCtrl(self,ctrlAttr = 'xxx.bb',inverse = 0 ):
    
        
        ctrl = str(ctrlAttr).split('.')[0]
        pma = ctrl+'_attrNromal_freezen_pma'
        
        normal_md = ctrl+'_attrNromal_normal_md'
        
        pos_md = ctrl+'_attrNromal_pos_md'
        neg_md = ctrl+'_attrNromal_neg_md'
        pos_clamp = ctrl+'_attrNromal_pos_clamp'
        neg_clamp = ctrl+'_attrNromal_neg_clamp'
        
        conditionNode = ctrl+'_attrNromal_condition'
        ####
        bridge = ctrl+'_attr_normal_bridge'
        if mc.objExists(bridge) == 0:
            mc.group( em =True ,n = bridge )
        
        
        if inverse == 0:
            posv= 1
            negv = -1
            
            driverPosV = 1
            driverNegV = -2
        else:
            posv= 1
            negv = -1
            
            driverPosV = 2
            driverNegV = -1
        
        mc.addAttr(bridge , ln = 'normalized_attr' ,k=True  )
        
        self.LZ_setDrivenKey( driverAttr = ctrlAttr , drivenAttr = str(bridge) + '.normalized_attr' , driverV=0, drivenV=0 )
        self.LZ_setDrivenKey( driverAttr = ctrlAttr , drivenAttr = str(bridge) + '.normalized_attr' , driverV = driverPosV, drivenV=posv )
        self.LZ_setDrivenKey( driverAttr = ctrlAttr , drivenAttr = str(bridge) + '.normalized_attr' , driverV = driverNegV, drivenV=negv )
        
        ani_node = self.findNode_animation( driver = ctrlAttr , driven = str(bridge) + '.normalized_attr'  )

        self.set_keytangent_type( animCurve = ani_node, type='linear')
        
        return [str( bridge ) + '.normalized_attr' , bridge ]
        
        
    def setDrivenFrame(self , bridge = '' , offsetGrp = ['upper','lower']):
        
        
        ##           upper close
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.upperlid_close' , drivenAttr = str(offsetGrp[0]) + '.rotateZ' , driverV=0, drivenV=0 )
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.upperlid_close' , drivenAttr = str(offsetGrp[0]) + '.rotateZ' , driverV=0.5, drivenV=-25 )
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.upperlid_close' , drivenAttr = str(offsetGrp[0]) + '.rotateZ' , driverV=1, drivenV=-50 )
        
        #self.LZ_setDrivenKey( driverAttr = str(bridge)+'.upperlid_open' , drivenAttr = str(offsetGrp[0]) + '.rotateZ' , driverV=0.5, drivenV=0 )
        #self.LZ_setDrivenKey( driverAttr = str(bridge)+'.upperlid_open' , drivenAttr = str(offsetGrp[0]) + '.rotateZ' , driverV=0, drivenV=-25 )
        
        
        
        ##           upper open
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.upperlid_open' , drivenAttr = str(offsetGrp[0]) + '.rotateZ' , driverV=0, drivenV=0 )
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.upperlid_open' , drivenAttr = str(offsetGrp[0]) + '.rotateZ' , driverV=1, drivenV=10 )
        
        
        ani_close_upper = self.findNode_animation( driver = str(bridge)+'.upperlid_close'  , driven = str(offsetGrp[0]) + '.rotateZ' )

        self.set_keytangent_type( animCurve = ani_close_upper, type='linear')
        
        ani_open_upper = self.findNode_animation( driver = str(bridge)+'.upperlid_open'  , driven = str(offsetGrp[0]) + '.rotateZ' )

        self.set_keytangent_type( animCurve = ani_open_upper, type='linear')
        
        
        ##           lower close
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.lowerlid_close' , drivenAttr = str(offsetGrp[1]) + '.rotateZ' , driverV=0, drivenV=0 )
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.lowerlid_close' , drivenAttr = str(offsetGrp[1]) + '.rotateZ' , driverV=0.5, drivenV= 25 )
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.lowerlid_close' , drivenAttr = str(offsetGrp[1]) + '.rotateZ' , driverV=1, drivenV= 50 )
        
        #self.LZ_setDrivenKey( driverAttr = str(bridge)+'.lowerlid_open' , drivenAttr = str(offsetGrp[1]) + '.rotateZ' , driverV=0.5, drivenV=0 )
        #self.LZ_setDrivenKey( driverAttr = str(bridge)+'.lowerlid_open' , drivenAttr = str(offsetGrp[1]) + '.rotateZ' , driverV=0, drivenV = 25 )
        #
        
        ##           lower open
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.lowerlid_open' , drivenAttr = str(offsetGrp[1]) + '.rotateZ' , driverV=0, drivenV=0 )
        self.LZ_setDrivenKey( driverAttr = str(bridge)+'.lowerlid_open' , drivenAttr = str(offsetGrp[1]) + '.rotateZ' , driverV=1, drivenV=-10 )
        
        
        ani_close_lower = self.findNode_animation( driver = str(bridge)+'.lowerlid_close'  , driven = str(offsetGrp[1]) + '.rotateZ' )

        self.set_keytangent_type( animCurve = ani_close_lower, type='linear')
        
        ani_open_lower = self.findNode_animation( driver = str(bridge)+'.lowerlid_open'  , driven = str(offsetGrp[1]) + '.rotateZ' )

        self.set_keytangent_type( animCurve = ani_open_lower, type='linear')
        
        
        
    def skinCluster_add_2_eyeGeo( self , headGeo = '' , skingeo = '' ,eyeOpenCloseJnts = ['',''] , followJnts = [ '' , '' ] ): 
        
        ifskin = self.IfSkined(  inputMesh = skingeo )
        
        if ifskin == 0:
            skinNode = mc.skinCluster( eyeOpenCloseJnts , skingeo ,normalizeWeights = 2 ,toSelectedBones =True )[0]
            mc.setAttr(str(skinNode)+'.normalizeWeights' , 1)
        else:
            skinNode = self.listSkinCluster(inputMesh = skingeo)
            jntInf = self.listAllSkined_joints( skinClus = skinNode )
            
            for jnt in eyeOpenCloseJnts:
                if jnt not in  jntInf :
                    mc.skinCluster( skinNode , e=True ,ai = jnt ,lw =True, wt = 0 ,fnw = True)
                    
        #### ==============   headGeo skin with reverse jnt ===========================
        ifskin_headgeo = self.IfSkined(  inputMesh = headGeo ) 
        
        
        
        if ifskin_headgeo == 0:
            skinNode = mc.skinCluster( followJnts , headGeo ,normalizeWeights = 2 ,toSelectedBones =True )[0]
            mc.setAttr(str(skinNode)+'.normalizeWeights' , 1)
        else:
            skinNode_headgeo = self.listSkinCluster(inputMesh = headGeo)

            jntInf = self.listAllSkined_joints( skinClus = skinNode_headgeo )

            for jnt in followJnts:
                if jnt not in  jntInf :
                    #print(skinNode_headgeo)
                    
                    mc.skinCluster( skinNode_headgeo , e=True ,ai = jnt ,lw =True, wt = 0 ,fnw = True)
        skinNode_headgeo = self.listSkinCluster(inputMesh = headGeo)   
        jntInf = self.listAllSkined_joints( skinClus = skinNode_headgeo )       
        for jnt in followJnts:
            reverseJnt = str(jnt)+'_reverse'
            
            if mc.objExists(reverseJnt) == True :
                self.connect_Skin_reverseMatrix( skin_node = skinNode_headgeo , jnt_con = jnt  ,reverseJnt = reverseJnt  )
        
        
    def wireDeformer_2_eyeGeo(self , inputMesh = '' , inputCurve = '' , wire_node = '' ):
        
        mc.wire(inputMesh,gw=1,en=1,ce=0,li=0,w = inputCurve ,n= wire_node )
        mc.setAttr(str(wire_node)+'.rotation',0)
    
         
    def eye_blendShape_settings(self ,inputMesh = 'xxx' ,locPre = '', prefix = 'xxx_', bridge = 'xxx' , open_uplid_Attr = 'xxx' , close_uplid_Attr = 'xxx', open_lowerlid_Attr = 'xxx' , close_lowerlid_Attr = 'xxx' ,crunchAttr = 'xxx' , expandAttr = 'xxx'):
        blend_node_name = inputMesh +'_blendNode'
        blendGrp = prefix+'eye_blendShape_grp'
        if mc.objExists(blendGrp) == 0:
            mc.group(em=True,n = blendGrp)
        
        
        num = 0 
        for i in [ open_uplid_Attr,close_uplid_Attr,open_lowerlid_Attr,close_lowerlid_Attr,crunchAttr,expandAttr ]: 
        
            if num == 1 or num == 3:
                
                targeMeshAll = prefix + locPre+i 
                driverAttibute = str(bridge)+'.'+ str(i)
                drivenAttibute = str(blend_node_name)+'.'+ str(targeMeshAll)
                
                mc.duplicate(inputMesh , n = targeMeshAll )
                mc.parent( targeMeshAll , blendGrp )
                self.AppendTarget(  targets = [targeMeshAll] , BlendMesh = inputMesh , blendshape_node = blend_node_name )
                
                self.LZ_setDrivenKey( driverAttibute , drivenAttibute , 0.5,0 )
                self.LZ_setDrivenKey( driverAttibute , drivenAttibute , 1,1 )
                
                ain_node = self.findNode_animation( driver = driverAttibute , driven = drivenAttibute )
                #print([ain_node,drivenAttibute])
                self.set_keytangent_type( animCurve = ain_node, type='linear')
                
                ######
                
                targeMeshHalf = prefix + locPre + i+'_half'
                driverAttibute = str(bridge)+'.'+ str(i)
                drivenAttibute = str(blend_node_name)+'.'+ str(targeMeshHalf)
                
                mc.duplicate(inputMesh , n = targeMeshHalf )
                mc.parent( targeMeshHalf , blendGrp )
                self.AppendTarget(  targets = [targeMeshHalf] , BlendMesh = inputMesh , blendshape_node = blend_node_name )
                
                self.LZ_setDrivenKey( driverAttibute , drivenAttibute , 0,0 )
                self.LZ_setDrivenKey( driverAttibute , drivenAttibute , 0.5,1 )
                
                ain_node = self.findNode_animation( driver = driverAttibute , driven = drivenAttibute )
                
                self.set_keytangent_type( animCurve = ain_node, type='linear')
                
            else:
                targeMesh = prefix + locPre + i 
                #print(targeMesh)
                driverAttibute = str(bridge)+'.'+ str(i)
                drivenAttibute = str(blend_node_name)+'.'+ str(targeMesh)
                
                mc.duplicate(inputMesh , n = targeMesh )
                mc.parent( targeMesh , blendGrp )
                self.AppendTarget(  targets = [targeMesh] , BlendMesh = inputMesh , blendshape_node = blend_node_name )
                
                self.LZ_setDrivenKey( driverAttibute , drivenAttibute , 0,0 )
                self.LZ_setDrivenKey( driverAttibute , drivenAttibute , 1,1 )
                
                ain_node = self.findNode_animation( driver = driverAttibute , driven = drivenAttibute )
                #print([ain_node,driverAttibute,drivenAttibute])
                self.set_keytangent_type( animCurve = ain_node, type='linear')
                
            num = num+1
        
    def create_inveseMatrax_jnt(self,jnts = [] , jntName = [] ):
        
        if len(jnts) == len(jntName) :
            for i in range(len(jnts)):
                self.LZ_creatJoint( jnts[i] ,jntName[i])
            
        
    def create_aimsetting(self ,prefix = '' , lfEyeTem = 'ac_lf_eye_temloc' ,rtEyeTem = 'ac_rt_eye_temloc' ,if_lf = 1 , if_rt = 1 ,valueAim = 20 ):
        
        eyeCtrl = prefix + 'ac_cn_lookAt_ctrl'
        lf_eye = prefix +'ac_lf_lookAt_ctrl'
        rt_eye = prefix +'ac_rt_lookAt_ctrl'
        
        lfTem =   lfEyeTem
        rtTem =   rtEyeTem
        
        lf_eyeBallZero = prefix +  'ac_lf_eyeball_ctrl_zero'
        rt_eyeBallZero = prefix +  'ac_rt_eyeball_ctrl_zero'
        
        
        lf_eyeBallOffset = prefix +  'ac_lf_eyeball_ctrl_offset'
        rt_eyeBallOffset = prefix +  'ac_rt_eyeball_ctrl_offset'
        
        ##--------
        #positionCenter  = mc.xform( grpTem , q=True ,ws=True ,t=True)[0]
        
        if mc.objExists( lfTem ) == 1 :
            eyeTem = lfTem
        else:
            if mc.objExists( rtTem ) == 1 :
                eyeTem = rtTem
            else:
                return None
        
        
        
        print(eyeTem)
        position_Eye = mc.xform(eyeTem , q=True ,ws=True ,t=True)
        
        centerGrp = mc.listRelatives( eyeTem , p=True )
        
        position_center = mc.xform(centerGrp , q=True ,ws=True ,t=True)
        

        dis = position_Eye[0] - position_center[0]
        
        scale_V = dis / 2
        
        if mc.objExists(eyeCtrl) == 0:  
            
            mc.group( em = True , n = eyeCtrl )
            self.creatControls_command( type = 21 ,curName = eyeCtrl , add = True )
            
            self.FG_addAttrs( objname=[eyeCtrl],attrname='head_space',dv=0,key=1,minValue=0,maxValue=1) 
            self.lockAttr(obj = eyeCtrl ,attr =['scaleX' ,'scaleY','scaleZ','visibility'])
            
            
            self.scaleCurveHull( eyeCtrl ,scale_V,scale_V,scale_V )

            mc.xform(  eyeCtrl , ws=True , t = ( 0 ,position_Eye[1],0) )
        
            zeroGrp = self.makeZeroGrpTwo( OrgObj = [eyeCtrl] , sufname = '_zero',cenObj='' , Mode = 0 , type = 'group',ro =True)
            ctrl_con = self.makeZeroGrpTwo( OrgObj = [eyeCtrl] , sufname = '_con',cenObj='' , Mode = 0 , type = 'group',ro =True)
        
        
        ##---------------------------
        if if_lf == 1:
            if mc.objExists(lf_eye) == 0:
                self.creatControls_command( type = 5 ,curName = lf_eye , add = False )
                self.rotateCurveHull(  curveName = lf_eye ,rx = 90,ry = 0, rz = 0 ,centerP = 1 )
                
                mc.parent( lf_eye ,eyeCtrl)
                self.resetAllAttrs( ctrl_obj = lf_eye )
                mc.setAttr(str(lf_eye)+ '.translateX' , dis )
                
                aim_influence = str(lf_eye) + '_aim'
                mc.group(em =True ,n = aim_influence )
                mc.parent( aim_influence ,  lf_eye )
                self.resetAllAttrs( ctrl_obj = aim_influence )
                
                self.makeZeroGrpTwo( OrgObj = [lf_eye] , sufname = '_zero',cenObj='' , Mode = 0 , type = 'group',ro =True)
                self.makeZeroGrpTwo( OrgObj = [lf_eye] , sufname = '_con',cenObj='' , Mode = 0 , type = 'group',ro =True)
                
                
                if mc.objExists(lf_eyeBallZero) == 1 and mc.objExists(lf_eyeBallOffset) == 1 :
                    mc.aimConstraint( aim_influence , lf_eyeBallOffset , worldUpType = 'objectrotation' , upVector = (0,1,0) , aimVector = ( 0 ,0,1) ,worldUpVector =(0,1,0) ,worldUpObject = lf_eyeBallZero  )
        
        if if_rt == 1:
            if mc.objExists(rt_eye) == 0:
                self.creatControls_command( type = 5 ,curName = rt_eye , add = False )
                self.rotateCurveHull(  curveName = rt_eye ,rx = 90,ry = 0, rz = 0 ,centerP = 1 )
                
                mc.parent( rt_eye ,eyeCtrl)
                self.resetAllAttrs( ctrl_obj = rt_eye )
                mc.setAttr(str(rt_eye)+ '.translateX' , dis*-1 )
                
                aim_influence = str(rt_eye) + '_aim'
                mc.group(em =True ,n = aim_influence )
                mc.parent( aim_influence ,  rt_eye )
                self.resetAllAttrs( ctrl_obj = aim_influence )
                
                
                
                
                self.makeZeroGrpTwo( OrgObj = [rt_eye] , sufname = '_zero',cenObj='' , Mode = 0 , type = 'group',ro =True)
                self.makeZeroGrpTwo( OrgObj = [rt_eye] , sufname = '_con',cenObj='' , Mode = 0 , type = 'group',ro =True)
                
                if mc.objExists(rt_eyeBallZero) == 1 and mc.objExists(rt_eyeBallOffset) == 1 :
                    mc.aimConstraint( aim_influence , rt_eyeBallOffset , worldUpType = 'objectrotation' , upVector = (0,1,0) , aimVector = ( 0 ,0,1) ,worldUpVector =(0,1,0) ,worldUpObject = rt_eyeBallZero  )
        
        mc.setAttr(str(zeroGrp[0]) + '.translateZ' , valueAim  )
        
        position_ctrl = mc.xform(eyeCtrl , q=True , ws=True ,t=True)
        
        
        followHead_loc = str(eyeCtrl).replace('_ctrl' , '_followHead')
        followBody_loc = str(eyeCtrl).replace('_ctrl' , '_followBody')
        
        self.createTransformer( locName = followHead_loc , position = position_ctrl ,rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
        self.createTransformer( locName = followBody_loc , position = position_ctrl ,rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0))
        
        
        self.makeZeroGrpTwo( OrgObj = [followHead_loc,followBody_loc] , sufname = '_zero',cenObj='' , Mode = 0 , type = 'group',ro =True)
        constraintName = str(eyeCtrl)+'_aim_constraint'
        mc.parentConstraint( followHead_loc , followBody_loc , ctrl_con[0] , mo =True, n = constraintName ) 
        
        
        driver_attr = str(eyeCtrl) + '.head_space'
        driven_attr01 = str(constraintName) + '.'  +str(followHead_loc) + 'W0'
        driven_attr02 = str(constraintName) + '.'  +str(followBody_loc) + 'W1'
        
        self.LZ_serDrivenKey_02( driverAttr = driver_attr , drivenAttr = driven_attr01 ,driverV = [0,1] , drivenV = [ 0 , 1 ] ,inType = 'linear' ,outType = 'linear' , preV = 'constant', poiV = 'constant')
        self.LZ_serDrivenKey_02( driverAttr = driver_attr , drivenAttr = driven_attr02 ,driverV = [0,1] , drivenV = [ 1 , 0 ] ,inType = 'linear' ,outType = 'linear' , preV = 'constant', poiV = 'constant')
        